package dal.object;

import gui.GameConstants;
import gui.event.Collision;

import java.awt.AlphaComposite;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Polygon;

public class MapObject3D extends MapObject {
	private Point origo;
	private Polygon hex;
	protected int r;
	protected int gap;
	
	public void setLocation(Point loc){
		origo = new Point(loc.x + GameConstants.picWidth50, loc.y + GameConstants.picHeight50);
		super.setLocation(loc);
		createPolygon();
	}
	
	/**
	 * representing a polygon for collision check
	 * the polygon is bigger then the visible object
	 */
	public void createPolygon(){		
		int ax = location.x + GameConstants.picWidth50;
		int ay = location.y - r;
		int bx = location.x + GameConstants.picWidth100 + r;
		int by = location.y + gap;
		int cy = location.y + (GameConstants.picHeight100 - gap);
		int dy = location.y + GameConstants.picHeight100 + r;
		int ex = location.x - r;
		
		int x[] = {ax, bx, bx, ax, ex, ex};
		int y[] = {ay, by, cy, dy, cy, by};
		
		hex = new Polygon(x, y, 6);
	}
	
	/**
	 * @param gr
	 * 	deletes the object image from the screen
	 */
	public void clear(Graphics2D gr){
		gr.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 0.0F));
		gr.fillPolygon(hex);
	}
	
	/**
	 * @return
	 * 	the object's center
	 */
	public Point getOrigo(){
		return origo;
	}
	
	/**
	 * @return
	 * 	a polygon representing the object's boundary
	 */
	public Polygon getHexagon(){
		return hex;
	}
	
	/**
	 * @param cld
	 * 	for collision response
	 */
	public void touch(Collision cld){
		cld.rockCollision();
	}
	
	/**
	 * @param cld
	 * 	for collision response
	 * the same as touch but happens when collision is stronger
	 */
	public void impact(Collision cld){
		cld.rockCollision();
	}
}
